package mscs.data;

import java.util.ArrayList;
import java.util.Date;
public class Store {
	private ArrayList<Goods> goodsList = new ArrayList<Goods>();
    private Date lastDate;
    public Store() {
    	this.goodsList = getOldStore().getGoodsList();
    	this.lastDate  = getOldStore().getLastDate();
    }
    public void update(ArrayList<Goods> goodsList) {
        this.goodsList.addAll(goodsList);
        lastDate = new Date();
    }
    public void save() {
    	//存储到文件
    }
    public Store getOldStore() {
    	return new Store();//从文件中取得存储对象
    }
    
    public ArrayList<Goods> getGoodsCollection(Goods goods) {
    	ArrayList<Goods> list = new ArrayList<Goods>();
		for(Goods goodsItr : goodsList)
			if(goodsItr.getId() == goods.getId())
				list.add(goodsItr);
		return list;
	}
    public int getSum(Goods goods) {
    	int sum = 0;
    	for(Goods goodsItr : goodsList) 
    		if (goodsItr.getId() == goods.getId())
    			sum++;
    	return sum;
    }
    
	public Date getLastDate() {
		return  lastDate;
	}
	public ArrayList<Goods> getGoodsList() {
		return goodsList;
	}
	public void setGoodsList(ArrayList<Goods> goodsList) {
		this.goodsList = goodsList;
	}
	public void setLastDate(Date lastDate) {
		this.lastDate = lastDate;
	}
	
}
